// 导入一些系统设置
import {port} from './seting.js'
// 引入koa
import Koa from 'koa'
import Router from 'koa-router'
// 实例化koa
const app = new Koa()
let router = new Router()

router.get('/',async(ctx , next)=>{

    const path = ctx.request.path
    
    if(ctx.request.path === '/'){
        
        ctx.response.body = `第一个页面:${path}`;
    }else{
        await next();
    }
})

router.get('/weixin',async(ctx , next)=>{
    if(ctx.request.path === '/weixin'){
        ctx.response.body = 'wx';
    }else{
        await next();
    }
})

router.get('/alipay',async(ctx , next)=>{
    if(ctx.request.path === '/alipay'){
        ctx.response.body = '支付宝';
    }else{
        await next();
    }
})

router.get('/ds',async(ctx , next)=>{
    if(ctx.request.path === '/ds'){
        ctx.response.body = 'gooooooooooodjjjjjjjjjj ???';
    }else{
        await next();
    }
})


router.get('/app',async(ctx,next)=>{
    
    
   

    const query = ctx.query; // 获取所以查询参数

    const code = ctx.query.code; // 获取code的值

    ctx.body = `查询参数：${JSON.stringify(query)}; ` ; 

    ctx.body += `\ncode 的值：${code}`
})




// 启动服务
app.use(router.routes());

app.listen(port,()=>{
    console.log(`该服务运行在：http://localhost:${port}`)
})

